package com.arges.web.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.arges.web.dao.GenericDao;
import com.arges.web.dao.PictureDao;
import com.arges.web.domain.bean.PictureBean;
import com.arges.web.domain.pojo.Picture;
import com.arges.web.page.PageInfo;
import com.arges.web.page.WebUtils;
import com.arges.web.service.PictureManager;

/**
 * 患者图像业务层
 *
 * @author zxj
 *
 */
@Service
public class PictureManagerImpl extends GenericManageImpl<Picture, PictureBean> implements PictureManager
{

	@Autowired
	private PictureDao pictureDao;

	@Override
	public GenericDao<Picture, Long> getGenericDao()
	{
		return pictureDao;
	}

	@Override
	public PageInfo<PictureBean> getPagePicture(PageInfo<Picture> pageInfo, String mrn)
	{
		PageInfo<PictureBean> beanPageInfo = null;
		Criterion conddition = null;
		if (StringUtils.isNotBlank(mrn))
		{
			conddition = Restrictions.eq("mrn", mrn);
		}
		PageInfo<Picture> pojoPageInfo = pictureDao.findAll(pageInfo, Picture.class, conddition);
		beanPageInfo = WebUtils.pojoToBeanPage(pojoPageInfo, PictureBean.class);
		return beanPageInfo;
	}

	@Override
	public PictureBean getpicture(Long id)
	{
		PictureBean pictureBean = null;
		Picture picture = pictureDao.get(id);
		if (null != picture)
		{
			pictureBean = new PictureBean();
			BeanUtils.copyProperties(picture, pictureBean);
		}
		return pictureBean;
	}

	@Override
	public List<PictureBean> getpictureList(String mrn)
	{
		Criterion criterion = Restrictions.eq("mrn", mrn);
		List<Picture> list = pictureDao.findDataByConditionAscString(criterion, "date");
		List<PictureBean> listBeans = new ArrayList<PictureBean>();
		for (Picture picture : list)
		{
			PictureBean pictureBean = new PictureBean();
			BeanUtils.copyProperties(picture, pictureBean);
			listBeans.add(pictureBean);
		}
		return listBeans;
	}

}
